<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/29
 * Time: 9:45
 */

namespace app\index\controller;
use think\Db;

class GoodsType
{
    public function left()
    {
        $where['is_delete'] = ['eq',1];
        $where['status'] = ['eq',1];
        $where['auding_status'] = ['eq',2];
        $where['count'] = [['eq',1],['eq',2],'or'];
        $data = Db::name('GoodsType')->where($where)->order('sort','asc')->select();
        $data = $this->get_cate($data);
        return ['code' => 200 , 'message' => '商品分类1 2级','data' => $data];

    }

    // 多层递归
    public function get_cate($arr, $fid = 0)
    {
        $newArr = array();
        foreach ($arr as $v) {
            if ($v["parenTid"] == $fid) {
                $newArr[] = array(
                    "id" => $v['id'],
                    "title" => $v['title'],
                    "son" => $this->get_cate($arr, $v['id']),
                );
            }
        }
        return $newArr;
    }

    public function right($id){
        $where['is_delete'] = ['eq',1];
        $where['status'] = ['eq',1];
        $where['auding_status'] = ['eq',2];
        $data = Db::name('GoodsType')->where(['parenTid' => $id])->order(['sort' => 'asc','id' => 'desc'])->field('id,title,picUrl')->select();
        return ['code' => 200 , 'message' => '商品分类3级','data' => $data];
    }
}